/*
 * @Author: 吕佳伟
 * @Date: 2021-04-25 22:42:22
 * @LastEditors: 吕佳伟
 * @LastEditTime: 2021-07-03 21:34:35
 * @Description: file content
 */
import 'package:flutter/material.dart';
import 'package:flutter_ijkplayer/flutter_ijkplayer.dart';

///课堂页面
///吕佳伟
class ClassIn extends StatefulWidget {
  ClassIn({Key key}) : super(key: key);

  @override
  _ClassInState createState() => _ClassInState();
}

class _ClassInState extends State<ClassIn> {
  IjkMediaController controller;
  List tabs = ["预习", "课堂", "作业", "考试"];
  int tabIndex = 1;

  @override
  void initState() {
    super.initState();
    this.controller = IjkMediaController();
    controller.setNetworkDataSource(
        'http://10.8.51.45:8000/live?port=1935&app=live&stream=1304',
        autoPlay: true);
  }

  @override
  Widget build(BuildContext context) {
    // ignore: non_constant_identifier_names
    String ClassId = ModalRoute.of(context).settings.arguments;
    return Scaffold(
      appBar: AppBar(
        title: Text("课堂页面"),
        actions: [
          IconButton(icon: Icon(Icons.video_call), onPressed: null),
        ],
      ),
      body: Container(
        child: ListView(
          children: [
            buildIjkPlayer(),
            TabBarBuilder(),
            interAct(),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.refresh),
        onPressed: () async {
          await controller.pause();
          await controller.play();
        },
      ),
    );
  }

  Widget buildIjkPlayer() {
    return Container(
      child: IjkPlayer(
        mediaController: controller,
      ),
    );
  }

  Widget TabBarBuilder() {
    return Container(
      height: 120,
      child: Row(
          children: tabs.map((e) {
        return Expanded(
          child: Row(
            children: [
              TextButton(
                  onPressed: () => changeTabs(tabs.indexOf(e)), child: Text(e))
            ],
          ),
          flex: 1,
        );
      }).toList()),
    );
  }

  Widget interAct() {
    return Container(
      child: interActDetails()[tabIndex],
    );
  }

  void changeTabs(index) {
    setState(() {
      this.tabIndex = index;
    });
  }

  ///交互功能
  List<Widget> interActDetails() {
    return [
      Container(
        child: ListView(
          shrinkWrap: true,
          children: [Text("预习测试1"), Text("预习测试2")],
        ),
      ),
      Container(
        child: Column(
          children: [
            Row(
              children: [
                Expanded(
                  child: Column(
                    children: [
                      TextButton(
                          onPressed: () => {print("nothing")},
                          child: Image.asset("assets/pics/qiandao.png")),
                      Text("签到")
                    ],
                  ),
                  flex: 1,
                ),
                Expanded(
                  child: Column(
                    children: [
                      TextButton(
                          onPressed: () => {print("nothing")},
                          child: Image.asset("assets/pics/test.png")),
                      Text("测试")
                    ],
                  ),
                  flex: 1,
                ),
                Expanded(
                  child: Column(
                    children: [
                      TextButton(
                          onPressed: () => {print("nothing")},
                          child: Image.asset("assets/pics/dianming.png")),
                      Text("点名")
                    ],
                  ),
                  flex: 1,
                ),
              ],
            ),
            Row(
              children: [
                Expanded(
                  child: Column(
                    children: [
                      TextButton(
                          onPressed: () => {print("nothing")},
                          child: Image.asset("assets/pics/wenjianxiafa.png")),
                      Text("文件下发")
                    ],
                  ),
                  flex: 1,
                ),
                Expanded(
                  child: Column(
                    children: [
                      TextButton(
                          onPressed: () => {print("nothing")},
                          child: Image.asset("assets/pics/vote.png")),
                      Text("投票")
                    ],
                  ),
                  flex: 1,
                ),
                Expanded(
                  child: Column(
                    children: [
                      TextButton(
                          onPressed: () => {print("nothing")},
                          child: Image.asset("assets/pics/tiwen.png")),
                      Text("提问")
                    ],
                  ),
                  flex: 1,
                ),
              ],
            ),
            Row(
              children: [
                Expanded(
                  child: Column(
                    children: [
                      TextButton(
                          onPressed: () => {print("nothing")},
                          child: Image.asset("assets/pics/qiangda.png")),
                      Text("抢答")
                    ],
                  ),
                  flex: 1,
                )
              ],
            )
          ],
        ),
      ),
      Container(
        child: Text("暂无作业"),
      ),
      Container(
        child: Text("暂无考试"),
      ),
    ];
  }
}
